#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long LL;
const int N = 2e6 + 10;

void solve()
{
    int n,m;
    cin >> n >> m;
    vector<vector<char>>arr  (n + 10,vector<char>(m + 10));
    for(int i = 1; i <= n; i ++)
        for(int j = 1; j <= m; j ++)
            cin >> arr[i][j];
    vector<vector<int>> dp1 (n + 10,vector<int>(m + 10,-1));
    vector<vector<int>> dp2 (n + 10,vector<int>(m + 10,-1));
    vector<vector<int>> dp3 (n + 10,vector<int>(m + 10,-1));
    for(int i = n; i; i --)
    {
        for(int j = m; j ; j --)
        {
            if(arr[i][j] == 'A') dp1[i][j] = 1;
            else dp[i][j] = 0;
            if((i + j) % 2 == 1) 
            {
                if(i == n) dp1[i][j] = dp1[i][j + 1];
                else if(j == m) dp1[i][j] = dp1[i + 1][j];
                else dp1[i][j] = dp1[i + 1][j] & dp1[i][j + 1];
            }
            else 
            {
                if(i == n) dp1[i][j] = dp1[i][j + 1];
                else if(j == m) dp1[i][j] = dp1[i + 1][j];
                else dp1[i][j] = dp1[i + 1][j] | dp1[i][j + 1];
            }
        }
    }
    if(dp1[1][1] == 1)
    {
        cout << "yes" << ' ';
    }
    else 
    {
        cout << "no" << ' ';
    }
    for(int i = n; i; i --)
    {
        for(int j = m; j ; j --)
        {
            if(arr[i][j] == 'A' || arr[i][j] == 'B') dp3[i][j] = 0;
            else if(i == n && j == m) dp3[i][j] = 1;
            if((i + j) % 2 == 1)
            {
                if(i == n) dp3[i][j] = dp3[i][j + 1];
                else if(j == m) dp3[i][j] = dp3[i + 1][j];
                else dp3[i][j] = dp3[i + 1][j] & dp3[i][j + 1];
            }
            else 
            {
                if(i == n) dp3[i][j] = dp3[i][j + 1];
                else if(j == m) dp3[i][j] = dp3[i + 1][j];
                else dp3[i][j] = dp3[i + 1][j] | dp3[i][j + 1];
            }
        }
    }
    if(dp3[1][1] == 0)
    {
        cout << "yes" << ' ';
    }
    else 
    {
        cout << "no" << ' ';
    }
    for(int i = n; i; i --)
    {
        for(int j = m; j ; j --)
        {
            
            if((i + j) % 2 == 1)
            {
                if(i == n) dp2[i][j] = dp2[i][j + 1];
                else if(j == m) dp2[i][j] = dp2[i + 1][j];
                else dp2[i][j] = dp2[i + 1][j] & dp2[i][j + 1];
            }
            else 
            {
                if(i == n) dp2[i][j] = dp2[i][j + 1];
                else if(j == m) dp2[i][j] = dp2[i + 1][j];
                else dp2[i][j] = dp2[i + 1][j] | dp2[i][j + 1];
            }
            if(arr[i][j] == 'B') dp2[i][j] = 1;
        }
    }
    if(dp2[1][1] == 1)
    {
        cout << "yes" << ' ';
    }
    else 
    {
        cout << "no" << ' ';
    }
    cout << endl;
}
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }
}